package com.chen.day01_base;

class Count {
    static Object lock = new Object();
    static int count = 0;

    public void add() {
        synchronized (lock) {
            count++;
        }
    }
}

public class ThreadTest {
    public static void main(String[] args) throws InterruptedException {
        Count count = new Count();
        Count count1 = new Count();

        Thread thread = new Thread(() -> {
            for (int i = 0; i < 500000; i++) {
                count.add();
            }

        });
        thread.start();
        Thread thread1 = new Thread(() -> {
            for (int i = 0; i < 500000; i++) {
                count1.add();
            }
        });
        thread1.start();


        thread1.join();
        thread.join();
        System.out.println(Count.count);
    }


}
